<template>
  <div>
    <div class="operation">
      <el-row :gutter="24">
        <el-col :span="16">
          <div>
            <el-button v-if="status==='0'" @click="showTaskDialog('insert')" class="slot-btn-top" type="primary" size="small">发放任务</el-button>
            <el-button v-if="status==='0'" @click="insertTask('day')" class="slot-btn-top" type="primary" size="small">每日任务</el-button>
            <el-button v-if="status==='0'" @click="insertTask('week')" class="slot-btn-top" type="primary" size="small">周总结</el-button>
            <el-button v-if="status==='0'" @click="insertTask('month')" class="slot-btn-top" type="primary" size="small">月总结</el-button>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="text-right">
            <el-button v-if="status==='0'" @click="openInstructions"   type="success" size="small">使用说明</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
    <!-- 任务列表 -->
    <el-table :data="status==='0'?dataList.slice((dataPagination.currentPage-1)*dataPagination.pageSize,dataPagination.currentPage*dataPagination.pageSize):dataList" :row-class-name="tableRowClassName" :highlight-current-row="true" stripe border class="table-index" :height="tableHeight" style="width: 100%;" :header-cell-style="getRowClass" v-loading="loading">
      <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
      <el-table-column prop="taskName" label="任务名称" sortable min-width="240"></el-table-column>
      <el-table-column prop="creatorName" label="任务创建人" sortable min-width="130"></el-table-column>
      <el-table-column prop="performerName" label="任务执行人" sortable min-width="130"></el-table-column>
      <el-table-column prop="finishDate" label="需完成时间" sortable min-width="170"></el-table-column>
      <el-table-column prop="isReceived" label="任务是否接收" :formatter="formatNeedTrain" sortable min-width="140"></el-table-column>
      <el-table-column prop="receivedDate" label="任务接收创建时间" sortable min-width="170"></el-table-column>
      <el-table-column prop="startDate" label="任务实际开始时间" sortable min-width="170"></el-table-column>
      <el-table-column prop="endDate" label="任务实际结束时间" sortable min-width="170"></el-table-column>
      <el-table-column prop="taskResult" label="任务结果" :formatter="formatNeed2Train" sortable min-width="130"></el-table-column>
      <el-table-column fixed="right" label="操作" sortable align="center" width="90">
        <template slot-scope="scope">
          <el-button @click="showTaskDialog('update',scope.row)" type="text" size="small">编辑</el-button>
          <el-button @click="showTaskDialog('delete',scope.row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :current-page="dataPagination.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="dataPagination.pageSize"
      layout="total, sizes, prev, pager, next, jumper" :total="dataPagination.total"></el-pagination>
    <!-- 任务弹框 -->
    <el-dialog :title="taskDialog.title" width="90%" top="30px" :visible.sync="taskDialog.isShow" :close-on-click-modal="false">
      <el-tabs v-model="taskDialog.activeName" @tab-click="handleClick" >
        <el-tab-pane  label="任务信息" name="1" v-if="status==='0'||taskDialog.formData.isEveryDayTask==='0'" :style="dialogHeightPane">
          <el-form :inline="true" class="demo-form-inline" :model="taskDialog.formData" :rules="taskDialog.rules" label-position="right" label-width="180px" >
            <h3 class="dialog-plate-title"><span>1、基本信息</span></h3>
            <el-form-item label="任务名称" prop="taskName">
              <el-input v-model="taskDialog.formData.taskName" :disabled="status!=='0'" class="width220"></el-input>
            </el-form-item>
            <el-form-item label="完成时间" prop="finishDate">
              <el-date-picker v-model="taskDialog.formData.finishDate"
              :disabled="status!=='0'"
              format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              placeholder="选择日期时间"
              class="width220">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="任务执行人所属部门" prop="dept">
              <el-select v-model="taskDialog.formData.dept" :disabled="status!=='0'" @change="changeDept" class="width220">
                <el-option v-for="item in deptors" :key="item.id" :label="item.deptName" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="任务执行人" prop="performer">
              <el-select v-model="taskDialog.formData.performer" :disabled="status!=='0'" class="width220">
                <el-option v-for="item in performName" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="任务创建人" prop="creatorName" v-if="taskDialog.type!=='insert'">
              <el-input v-model="taskDialog.formData.creatorName" disabled  class="width220"></el-input>
            </el-form-item>
            <el-form-item label="任务创建时间" prop="createDate" v-if="taskDialog.type!=='insert'" >
              <el-input v-model="taskDialog.formData.createDate" disabled class="width220"></el-input>
            </el-form-item>
           <el-form-item label="任务说明" class="form-item-block">
              <quill-editor v-if="taskDialog.type === 'insert'"  class="task" v-model="taskDialog.formData.taskContent"></quill-editor>
             <div v-else class="fileContent">
              <el-button @click="showExplainDialog('info','insert')" :disabled="status!=='0' " type="primary" size="small">新增任务说明</el-button>
              <el-table :data="taskDialog.taskInfoList" stripe border :header-cell-style="getRowClass">
                <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                <el-table-column prop="time" label="填写时间" sortable min-width="170"></el-table-column>
                <el-table-column prop="content" label="填写内容" sortable min-width="500">
                  <template  slot-scope="scope">
                    <div v-html="scope.row.content"></div>
                  </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                  <template slot-scope="scope">
                      <el-button @click="showExplainDialog('info','update',scope.row)" :disabled="status!=='0' " type="text" size="small">编辑</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-form-item>

          <div v-if="taskDialog.type!=='insert'">
            <h3 class="dialog-plate-title" ><span>2、接收信息</span></h3>
            <el-form-item label="任务是否接收">
              <el-select v-model="taskDialog.formData.isReceived" :disabled="status==='0'" class="width220">
                <el-option label="【空】" value="-1"></el-option>
                <el-option label="否" value="0"></el-option>
                <el-option label="是" value="1"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="接收创建时间">
              <el-date-picker v-model="taskDialog.formData.receivedDate" disabled format="yyyy-MM-dd HH:mm:ss" type="datetime" class="width220"></el-date-picker>
            </el-form-item>
            <el-form-item label="任务接收说明">
             <el-button  @click="showExplainDialog('receive','insert')" :disabled="status!=='1'" type="primary" size="small">新增接收说明</el-button>
              <el-table :data="taskDialog.taskReceiveList" stripe border :header-cell-style="getRowClass">
              <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
              <el-table-column prop="time" label="填写时间" sortable min-width="170"></el-table-column>
              <el-table-column prop="content" label="填写内容" sortable min-width="500">
                <template  slot-scope="scope">
                  <div v-html="scope.row.content"></div>
                </template>
              </el-table-column>
                <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                  <template slot-scope="scope">
                    <el-button @click="showExplainDialog('receive','update',scope.row)" :disabled="status==='0'" type="text" size="small">编辑</el-button>
                  </template>
                </el-table-column>
              </el-table>
              </el-form-item>
            <h3 class="dialog-plate-title"><span>3、开始信息</span></h3>
            <el-form-item label="任务实际开始时间">
              <el-date-picker v-model="taskDialog.formData.startDate" :disabled="status==='0'"
                format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间"
               class="width220"></el-date-picker>
            </el-form-item>
            <el-form-item label="开始创建时间">
              <el-input v-model="taskDialog.formData.startCreateDate" disabled class="width220"></el-input>
            </el-form-item>

            <h3 class="dialog-plate-title"><span>5、结束信息</span></h3>
            <el-form-item label="任务实际结束时间">
                <el-date-picker v-model="taskDialog.formData.endDate" :disabled="status==='0'"
                format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间"
                class="width220"></el-date-picker>
              </el-form-item>
              <el-form-item label="结束创建时间">
                  <el-input v-model="taskDialog.formData.endDateCreateDate" disabled class="width220"></el-input>
              </el-form-item>
              <el-form-item label="任务结果">
                  <el-select v-model="taskDialog.formData.taskResult" :disabled="status==='0'" class="width220">
                      <el-option label="【空】" value="-1"></el-option>
                      <el-option label="完成" value="1"></el-option>
                      <el-option label="未完成" value="0"></el-option>
                  </el-select>
              </el-form-item>
              <el-form-item label="自我评价">
                <el-select v-model="taskDialog.formData.taskSelfEvaluation"
                  :disabled="status==='0'"  class="width220">
                  <el-option label="【空】" value="-1"></el-option>
                  <el-option label="差" value="1"></el-option>
                  <el-option label="良好" value="2"></el-option>
                  <el-option label="优秀" value="3"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="自我评价说明" class="form-item-block">
                  <quill-editor class="task" v-model="taskDialog.formData.taskSelfDescription"
                  :disabled="status==='0'"  @focus="!dialogListDisabled.taskSelfDescription? onEditorFocus($event) : ''"
                   style="padding-right: 10px;"></quill-editor>
              </el-form-item>

              <h3 class="dialog-plate-title"><span>6、复核信息</span></h3>
              <el-form-item label="任务是否复核">
                <el-select v-model="taskDialog.formData.isReviewTask" :disabled="status!=='0'"  class="width220">
                  <el-option label="【空】" value="-1"></el-option>
                  <el-option label="否" value="0"></el-option>
                  <el-option label="是" value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="复核结果">
                <el-select v-model="taskDialog.formData.reviewResult" :disabled="status!=='0'"  class="width220">
                  <el-option label="【空】" value="-1"></el-option>
                  <el-option label="通过" value="1"></el-option>
                  <el-option label="不通过" value="0"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="复核创建时间">
                <el-input v-model="taskDialog.formData.reviewTime" disabled  class="width220"></el-input>
              </el-form-item>
              <el-form-item label="任务复核说明" class="form-item-block">
                <quill-editor class="task" v-model="taskDialog.formData.reviewDescription"
                  @focus="!dialogListDisabled.reviewDescription? onEditorFocus($event) : ''"
                  :disabled="status!=='0'"></quill-editor>
              </el-form-item>
          </div>
          <el-form-item  class="form-item-block text-center" >
             <el-button @click="submitList"  type="primary">确 定</el-button>
          </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane :label="taskDialog.formData.isEveryDayTask>1?taskDialog.formData.taskName:'4、过程信息'" name="2" v-if="taskDialog.type!=='insert'" :style="dialogHeightPane">
          <div :style="dialogHeightPane" v-if="taskDialog.formData.isEveryDayTask>1">
            <processDetail :detailData="taskDialog.processDetail" @successSubmit="successSubmit1"></processDetail>
          </div>
          <div v-else>
            <el-button v-if="status!=='0'" @click="showProcessDialg('insert')" type="primary" size="small">新增</el-button>
            <el-table :data="processStateData" stripe border class="table-index"  style="width: 100%;" :header-cell-style="getRowClass">
              <el-table-column fixed type="index" label="*" sortable min-width="40" align="center"></el-table-column>
              <el-table-column prop="taskDescription" label="任务说明" show-overflow-tooltip sortable min-width="280" align="center"></el-table-column>
              <el-table-column prop="startDate" label="开始时间" sortable min-width="170" align="center"></el-table-column>
              <el-table-column prop="endDate" label="结束时间" sortable min-width="170" align="center"></el-table-column>
              <el-table-column prop="creatTime" label="创建时间" sortable min-width="170" align="center"></el-table-column>
              <el-table-column prop="managerName" label="主管" sortable align="center"></el-table-column>
              <el-table-column prop="managerAdvice" label="主管意见" show-overflow-tooltip sortable min-width="200" align="center"></el-table-column>
              <el-table-column  label="类型" min-width="60" align="center">
                <template slot-scope="scope">
                  <el-tag v-if="scope.row.isNowTime==='1'"  size="mini" type="success">实时</el-tag>
                  <el-tag type="info" v-else size="mini">补录</el-tag>
                </template>
              </el-table-column>
              <el-table-column  label="状态" min-width="100" align="center">
                <template slot-scope="scope">
                  <el-tag v-if="scope.row.endDate" type="success" size="mini"  :hit="true">已完成</el-tag>
                  <el-tag type="danger" v-else size="mini" :hit="true">进行中...</el-tag>
                </template>
              </el-table-column>
              <el-table-column fixed="right" label="操作" sortable align="center" width="200">
                <template slot-scope="scope">
                  <el-button size="small" type="text" @click="showProcessDialg('update',scope.row)" ><el-link type="primary">编辑</el-link></el-button>
                  <el-button size="small" type="text" @click="showProcessDialg('finish',scope.row)"  v-if="scope.row.isNowTime==='1'&&!scope.row.endDate"><el-link type="success">结束</el-link></el-button>
                  <el-button size="small" type="text" @click="showProcessDialg('delete',scope.row)"><el-link type="danger">删除</el-link></el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
        <el-tab-pane label="附件" name="3" v-if="taskDialog.type!=='insert'" :style="dialogHeightPane">
          <div :style="dialogHeightPane">
            <!-- 附件上传按钮 -->
            <el-form label-position="right" label-width="110px" :model="enclosureData" v-loading="enclosureData.loading">
              <el-form-item label="选择文件">
                <el-upload class="upload-demo" style="width: 99%;margin: 0 auto;"
                  ref="uploadEnclosure"
                  action="string" :auto-upload="false" :limit="1"
                  :http-request="uploadSectionFile">
                <el-button  slot="trigger" size="small" type="primary">上传附件</el-button>
              </el-upload>
              </el-form-item>
              <el-form-item label="文件描述"><el-input v-model="enclosureData.fileDesc" type="textarea" style="padding-right: 10px;box-sizing: border-box;"></el-input></el-form-item>
            </el-form>
            <div style="margin-top: 20px;text-align: right;padding-right: 10px;"><el-button  @click="submitEnclosure" type="primary">提交</el-button></div>
             <!-- 附件列表 -->
            <h3 class="dialog-plate-title" style="margin: 0px 0 10px;padding-right: 10px;box-sizing: border-box;"><span>已上传附件列表</span></h3>
            <el-table :data="enclosureList" stripe border class="user-table" height="550" style="width: 99%;" :header-cell-style="getRowClass">
              <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
              <el-table-column prop="fileName" label="文件名称" sortable min-width="300"></el-table-column>
              <el-table-column prop="uploadPersonName" label="文件上传人" sortable min-width="130"></el-table-column>
              <el-table-column prop="uploadTime" label="文件上传时间" sortable min-width="170"></el-table-column>
              <el-table-column prop="fileDesc" label="文件描述" sortable min-width="400"></el-table-column>
              <el-table-column fixed="right" label="操作" sortable align="right" min-width="90">
                <template slot-scope="scope">
                  <el-button @click="downloadEnclosure(scope.row)" type="text" size="small">下载</el-button>
                  <el-button @click="deleteEnclosure(scope.row)" type="text" size="small">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
  <!-- 新增-insert 编辑-update 任务说明 任务接收说明  -->
    <el-dialog :title="explainDialog.title" width="600px" center :visible.sync="explainDialog.isShow" :close-on-click-modal="false" style="padding-bottom: 15px;">
      <el-form :inline="true" class="demo-form-inline" :model="explainDialog.formData" label-position="right" label-width="80px">
        <el-form-item label="填写内容">
          <quill-editor v-model="explainDialog.formData.content"></quill-editor>
        </el-form-item>
        <el-form-item class="form-item-block text-center">
          <el-button @click="submitExplainDialog" type="primary">确 定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 过程详情 -->
    <el-dialog :title="processDialog.title" width="900px" center  :visible.sync="processDialog.isShow" :close-on-click-modal="false" style="padding-bottom: 15px;">
      <processDetail :detailData="processDialog" @successSubmit="successSubmit"></processDetail>
    </el-dialog>
     <!-- 使用说明 -->
    <el-dialog title="使用说明" width="1000px" top="50px" :visible.sync="instructionsDialog.isShow" :close-on-click-modal="false">
      <div :style="instructionsDialog.instructionsHeight">
        <div style="overflow: hidden;margin-bottom: 20px;">
          <el-upload class="upload-demo"
          style="width: 99%;margin: 0 auto;"
          ref="uploadDraw"
          :action="instructionsDialog.appendixUrl"
          :on-success="uploadDrawSuccess"
          :on-error="uploadDrawError"
          :limit="1">
            <el-button slot="trigger" size="small" type="primary" >上传图纸文件</el-button>
          </el-upload>
        </div>
        <div style="overflow: hidden;">
          <div style="width: 99%;margin: 0 auto;">
            <el-input v-model.number="instructionsDialog.pdfOption.drawingPage" type="number" style="width: 150px;" min="1" :max="instructionsDialog.pdfOption.drawingNumPages"></el-input>
            <span>/{{instructionsDialog.pdfOption.drawingNumPages}}</span>
            <el-button @click="instructionsDialog.pdfOption.drawingRotate += 90">&#x27F3;</el-button>
            <el-button @click="downloadAppendixPDF">下载</el-button>
            <pdf ref="drawingPdf"
              style="border: 1px solid red;display: block;"
              :src="instructionsDialog.pdfOption.drawingSrc"
              :page="instructionsDialog.pdfOption.drawingPage"
              :rotate="instructionsDialog.pdfOption.drawingRotate"
              @progress="drawingLoadedRatio = $event"
              @num-pages="instructionsDialog.pdfOption.drawingNumPages = $event"
              @link-clicked="instructionsDialog.pdfOption.drawingPage = $event">
            </pdf>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import pdf from 'vue-pdf';
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
import {quillEditor} from 'vue-quill-editor';
import api from '@/axios/api.js'
import creatingValueApi from '@/axios/creatingValueApi.js'
import processDetail from './components/processDetail.vue'
export default {
  name: "",
  components: {pdf,quillEditor,processDetail},
  data() {
    return {
      status:'0',
      loading:false,
      dataList:[],/**任务列表 */
      dataPagination:{/**任务列表分页 */
        pageSize:10,
        currentPage:1,
        total:0
      },
      tableHeight:null,
      deptors:[],/**执行部门列表 */
      performName:[],/**执行人列表 */
      /**任务弹框*/
      taskDialog:{
        type:'',
        title:'',
        isShow:false,
        activeName:'1',
        formData:{},
        taskInfoList:[],/**任务说明列表 */
        taskReceiveList:[],/**任务接收说明 */
        processDetail:{
          title:'',
          type:'',
          isEveryDayTask:'',
          formData:{}
        },/**周计划或月计划过程信息详情 */
        rules:{
          taskName:[{required: true, message: '请输入任务名称', trigger: 'blur' }],
          finishDate:[{required: true, message: '请输入任务名称', trigger: 'blur' }],
          dept:[{required: true, message: '请输入任务名称', trigger: 'blur' }],
          performer:[{required: true, message: '请输入任务名称', trigger: 'blur' }]
        }
      },
      explainDialog:{
        title:'',
        isShow:false,
        type:'',
        explainType:'',
        formData:{}
      },
      processStateData:[],/**过程信息列表 */
      processDialog:{/**过程详情弹框 */
        title:'',
        type:'',
        isShow:false,
        isEveryDayTask:'',
        formData:{}
      },/**过程详情 */
      /**使用说明弹框 */
      instructionsDialog:{
        isShow:false,
        instructionsHeight: {
          height: (document.documentElement.clientHeight - 210) + 'px',
          overflowY: 'auto'
        },
        appendixUrl:creatingValueApi.uploadInstructionsUrl(),
        pdfOption:{
          drawingPage: 1,
          drawingNumPages:0,
          drawingRotate: 0,
          drawingSrc:"",
          drawingLoadedRatio: 0,
        }
      },
      dialogHeightPane: {
        height: (document.documentElement.clientHeight - 180) + 'px',
        overflowY: 'auto'
      },
      enclosureData:{
        loading:false,
        fileDesc:'',/**文件描述 */
      },
      enclosureList:[],/**附件列表 */
    };
  },
   watch: {
    $route(){
      this.status = this.$route.query.status;
      this.tableHeight = this.status === '0' ? (document.documentElement.clientHeight - 160) : (document.documentElement.clientHeight - 130)
      this.getData();
    }
  },
  created() {
  },
  mounted(){
    this.status = this.$route.query.status;
    this.tableHeight = this.status === '0' ? (document.documentElement.clientHeight - 160) : (document.documentElement.clientHeight - 130)
    this.getData();
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
      if (this.status==='0') {
        if (row.isPerformerUpdate){
          if (row.isPerformerUpdate == 1){
            return 'success-row';
          }
        }
      } else if (this.status==='1') {
        if (row.isCreatorUpdate){
          if (row.isCreatorUpdate == 1){
            return 'success-row';
          }
        }
      }
      return '';
    },
    getData() {
      let self = this;
      let type='';
      self.loading = true;
      switch(self.status ){
        case '0'://获取下发交办任务列表
          api.assignmentList().then(res=>{
            self.loading=false;
            self.dataList = res.content;
          },error=>{
            self.loading=false;
          })
            return
          break;
        case '1'://0-待办交办任务
            type=0;
          break;
        case '2'://1-已办交办任务
            type=1;
          break;
      }
      api.getMyTaskManager(type,{
        pageSize:self.dataPagination.pageSize,
        currentPage:self.dataPagination.currentPage,
      }).then(res=>{
        self.dataList = res.content.records;
        self.dataPagination.total=res.content.total;
        self.loading=false;
      },error=>{
        self.loading=false;
      })
    },
    handleSizeChange: function (size) {
      this.dataPagination.pagesize = size;
      if(this.status!=="0"){
        this.getData()
      }
    },
    handleCurrentChange: function (currentPage) {
      this.dataPagination.pagesize = 1;
      this.dataPagination.currentPage = currentPage;
      if(this.status!=="0"){
        this.getData()
      }
    },
    /**发放任务*/
    showTaskDialog(type,row){
      let self = this;
      self.taskDialog.type = type;
      switch(type){
        case 'insert':
          self.taskDialog.title = '新增任务'
          self.taskDialog.activeName="1";
          self.taskDialog.isShow = true;
          self.taskDialog.formData ={}
          self.getDepts();
        break;
        case 'update':
          self.taskDialog.isShow = true;
          self.taskDialog.formData = JSON.parse(JSON.stringify(row));
          self.taskDialog.formData.dept = Number(self.taskDialog.formData.dept);
          self.taskDialog.formData.performer = Number(self.taskDialog.formData.performer);
          self.taskDialog.title = '编辑任务'
          if( self.taskDialog.formData.isEveryDayTask==='0'){
            self.taskDialog.activeName='1';
            self.getDepts();
            self.getPerform(row.dept);
            self.getMissionData();
            self.getTaskReceiveList();
          }else{
            self.taskDialog.activeName='2';
            if(self.taskDialog.formData.isEveryDayTask>1){
              self.getProcessStateData(()=>{
                if(self.processStateData.length>0){
                  self.taskDialog.processDetail={
                    type:'update',
                    title:`编辑${self.taskDialog.formData.isEveryDayTask==='2'?'周总结':(self.taskDialog.formData.isEveryDayTask==='3'?'月总结':'')}`,
                    formData:JSON.parse(JSON.stringify(self.processStateData[0]))
                  }
                }else{
                  self.taskDialog.processDetail={
                    type:'insert',
                    title:`新增${self.taskDialog.formData.isEveryDayTask==='2'?'周总结':(self.taskDialog.formData.isEveryDayTask==='3'?'月总结':'')}`,
                    formData:{taskId:self.taskDialog.formData.id}
                  }
                }
                self.taskDialog.processDetail.isEveryDayTask = self.taskDialog.formData.isEveryDayTask
              })
            }else{
              self.getProcessStateData();
            }
          }
        break;
        case 'delete':
          self.$confirm('是否删除此任务？', '提示', {
            confirmButtonClass: 'el-button--warning'
          }).then(() => {
            if(self.status==='0'){
              creatingValueApi.deleteTask1(row.id).then(res=>{
                self.$message.success("删除成功")
                self.getData();
              })
            }else if(self.status==='1'){
              creatingValueApi.deleteTask2(row.id).then(res=>{
                self.$message.success("删除成功")
                self.getData();
              })
            }

          }).catch(() => {});
          break;
      }
    },
    /**切换tab */
    handleClick(tab, event){
      let self= this;
      switch(tab.name){
        case '2':
          self.getProcessStateData();
          break;
        case '3':
          self.getEnclosureList();
          break;

      }
    },
    /**新增任务 */
    insertTask(type){
      let self = this;
      self.$confirm(`是否生成${type==='day'?'每日任务':type==='week'?'周总结':'月总结'}`,{
        confirmButtonClass: 'el-button--warning'
      }).then(()=>{
        switch(type){
          case 'day':
            creatingValueApi.insertEverDayTask().then(res=>{
            self.$message.success('已经创办每日任务！');
          });
          break;
          case 'week':
            creatingValueApi.insertWeekTask().then(res=>{
              self.$message.success('已经创建周总结！');
            })
            break;
            case 'month':
              creatingValueApi.insertMonthTask().then(res=>{
                 self.$message.success('已经创建月总结！');
              })
            break;
          }
      })
    },
    /**获取部门*/
    getDepts() {
      let self = this;
      api.selectDepts().then(res=>{
        self.deptors = res.content;
      })
    },
    changeDept(){
       this.getPerform(this.taskDialog.formData.dept)
    },
    /**获取任务执行人 */
    getPerform(id) {
      let self = this;
      api.taskPerformPerson(id).then(res=>{
        self.performName = res.content;
      });
    },
    //获取任务说明列表
    getMissionData() {
      let self = this;
      creatingValueApi.getTaskInfoList(self.taskDialog.formData.id).then(res=>{
        self.taskDialog.taskInfoList=res.content;
      })
    },
    //获取任务接收说明列表
    getTaskReceiveList(){
      let self = this;
      creatingValueApi.getTaskReceiveList(self.taskDialog.formData.id).then(res=>{
        self.taskDialog.taskReceiveList=res.content
      })
    },
    /**点击弹出新增或编辑任务说明或任务接收说明 */
    showExplainDialog(explainType,type,row){
      let self = this;
      self.explainDialog.explainType= explainType;
      self.explainDialog.type= type;
      self.explainDialog.isShow = true;
      switch(type){
        case 'insert':
           self.explainDialog.title = `新增${self.explainDialog.explainType==='info'?'任务说明':'任务接收'}`;
           self.explainDialog.formData={};
          break;
        case 'update':
          self.explainDialog.title = `编辑${self.explainDialog.explainType==='info'?'任务说明':'任务接收'}`;
          self.explainDialog.formData = row;
          break;
      }
    },
    /**预览使用说明*/
    openInstructions(){
      this.instructionsDialog.isShow = true;
      this.instructionsDialog.pdfOption.drawingPage = 1;
      this.instructionsDialog.pdfOption.instructionsPage = 1;
      this.instructionsDialog.pdfOption.drawingSrc = creatingValueApi.viewInstructionsUrl();
    },
    /**上传使用说明成功*/
    uploadDrawSuccess(response, file, fileList) {
      if (response.statusCode == 200) {
        this.$refs.uploadDraw.clearFiles();
        this.$message.success('上传成功');
        this.instructionsDialog.pdfOption.drawingSrc="";
        this.instructionsDialog.isShow = false;
      } else {
        this.$message.error(response.desc)
      }
    },
    /**上传使用说明失败*/
    uploadDrawError(response, file, fileList) {
      this.$message.error(response);
    },
    /**下载pdf */
    downloadAppendixPDF() {
      window.location.href =creatingValueApi.downloadInstructionsUrl();
    },
    //获取过程状态信息列表
    getProcessStateData(cb) {
      let self = this;
      creatingValueApi.taskManagerdetail(self.taskDialog.formData.id).then(res=>{
        self.processStateData = res.content;
        cb?cb():'';
      })
    },
    /**新增修改下发的任务 */
    submitList(){
      let self = this,
      postData = JSON.parse(JSON.stringify(self.taskDialog.formData));
      postData.finishDate =postData.finishDate?self.timestampToTime1(postData.finishDate):null;
      postData.startDate =postData.startDate?self.timestampToTime1(postData.startDate):null;
      postData.endDate =postData.endDate?self.timestampToTime1(postData.endDate):null;
      creatingValueApi.insertUpdateIssuedTask(self.taskDialog.type,postData).then(res=>{
        self.taskDialog.isShow = false;
        self.$message.success(`${self.taskDialog.title}成功`);
        self.getData();
      })
    },
    /**提交任务说明 和任务接收说明 */
    submitExplainDialog(){
      let self = this;
      let postData = JSON.parse(JSON.stringify(self.explainDialog.formData));
      if(self.explainDialog.type==='update'){
         creatingValueApi.insertUpdateTaskInfo(postData,'update').then(res=>{
            self.explainDialog.isShow=false;
            self.$message.success(`${self.explainDialog.title}成功`);
            self.explainDialog.explainType==='info'?self.getMissionData():self.getTaskReceiveList();
         })
      }else{
        postData.tid = self.taskDialog.formData.id;
        creatingValueApi.insertUpdateTaskInfo(postData,'insert',self.explainDialog.explainType==='info'?1:2).then(res=>{
          self.explainDialog.isShow=false;
          self.$message.success(`${self.explainDialog.title}成功`);
          self.explainDialog.explainType==='info'?self.getMissionData():self.getTaskReceiveList()
        })
      }
    },
    showProcessDialg(type,row){
      let self = this;
      self.processDialog.type = type;
      self.processDialog.isEveryDayTask = self.taskDialog.formData.isEveryDayTask;
      switch(type){
        case 'insert':
          self.processDialog.isShow = true;
          self.processDialog.title = '新增过程信息';
          self.processDialog.formData = {
            taskId:self.taskDialog.formData.id,
            isNowTime:'1',
            startDate:self.timestampToTime1(new Date())
          }
          break;
        case 'update':
          self.processDialog.isShow = true;
          self.processDialog.title = '编辑过程信息';
          self.processDialog.formData = row;
          break;
        case 'finish':
          self.$confirm('是否结束本次任务过程?', '提示', {
            confirmButtonClass: 'el-button--warning'
          }).then(() => {
            row.endDate=self.timestampToTime1(new Date());
            creatingValueApi.insertUpdateProcessDetail('update',row).then(res=>{
                self.getProcessStateData();
                self.$message.success(`本次过程结束成功！`)
              })
            }).catch(() => {});
          break;
        case 'delete':
          self.$confirm('是否删除本次任务过程信息?', '提示', {
            confirmButtonClass: 'el-button--warning'
          }).then(() => {
            creatingValueApi.deleteTaskProcessDetail(row.id).then(res=>{
              self.getProcessStateData();
              self.$message.success("删除成功！")
          });
          }).catch(() => {});
          break;
      }
    },
    successSubmit(){
      this.processDialog.isShow = false;
      this.getProcessStateData();
    },
    successSubmit1(){
      this.taskDialog.isShow = false;
      this.getData();
    },
     //获取附件列表
    getEnclosureList() {
      let self = this;
      creatingValueApi.getEnclosureList(self.taskDialog.formData.id).then(res=>{
        self.enclosureList = res.content;
      })
    },
    uploadSectionFile(param){
      let self =this;
      self.enclosureData.loading = true;
      let fileObj = param.file;
      let form =new FormData();
      let postData={
        tid:self.taskDialog.formData.id,
        fileDesc:self.enclosureData.fileDesc
      };
      form.append('taskManagerAttchment',JSON.stringify(postData));
      form.append('file',fileObj);
      creatingValueApi.insertEnclosure(form).then(res=>{
        self.enclosureData.loading = false;
        self.$message.success(`附件新增成功`);
        self.enclosureData.fileDesc='';
        self.$refs.uploadEnclosure.clearFiles();
        self.getEnclosureList();
      },error=>{
        self.enclosureData.loading = false;
      })
    },
    /**点击新增附件 */
    submitEnclosure(){
      let self = this;
      if(self.$refs.uploadEnclosure.uploadFiles.length>0){
        self.$refs.uploadEnclosure.submit()
      }else{
         self.$message.error(`请选择附件！`)
      }
    },
    /**删除附件 */
    deleteEnclosure(row){
      let self = this;
      this.$confirm('是否删除此附件?', '提示', {
          confirmButtonClass: 'el-button--warning'
      }).then(() => {
        creatingValueApi.deleteEnclosure(row.id).then(res=>{
          self.$message.success('附件删除成功！')
          self.getEnclosureList();
        })
      }).catch(() => {});
    },
    /**下载附件 */
    downloadEnclosure(row){
      window.location.href = creatingValueApi.downloadEnclosure(row.id);
    }
  }
}
</script>
<style scoped>
</style>
